package com.sky.controller.admin;

import com.qcloud.cos.model.UploadResult;
import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import com.sky.utils.CosUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.UUID;


@RestController
@RequestMapping("/admin/common")
@Api(tags = "公共接口")
@Slf4j
public class CommonController {

    @PostMapping("/upload")
    public Result<String> upload( @RequestParam("file") MultipartFile file){
        try {
            String filename=file.getOriginalFilename();
            filename=UUID.randomUUID()+ filename.substring(filename.lastIndexOf("."));
            UploadResult upload = CosUtil.upload(file.getInputStream(), file.getSize(),filename);
            return Result.success(upload.getKey());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return Result.error("");
    }
}
